package cn.edu.neusoft.maxingxin231.yuejian06.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.PostCommentBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Listener.ListListener;
import cn.edu.neusoft.maxingxin231.yuejian06.R;

public class PostCommentAdapter extends RecyclerView.Adapter<PostCommentViewHolder>  {

    List<PostCommentBean> items;
    int layoutResource;
    String id,comment_text,comment_time;

    public PostCommentAdapter(ListListener<PostCommentBean> context, List<PostCommentBean> items, int layoutResource){

        this.items = items;
        this.layoutResource = layoutResource;
    }


    @NonNull
    @Override
    public PostCommentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(parent.getContext())
                .inflate(R.layout.commentlist_card,parent,false);
       // PostCommentViewHolder postCommentViewHolder = new PostCommentViewHolder(itemView);
        return new PostCommentViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull PostCommentViewHolder holder, int position) {
       PostCommentBean postCommentBean = (PostCommentBean) items.get(position);
       if (postCommentBean ==null) return;
       PostCommentViewHolder postCommentViewHolder = (PostCommentViewHolder) holder;
        postCommentViewHolder.tv_com1.setText(postCommentBean.getUser_name());
        postCommentViewHolder.tv_com2.setText(postCommentBean.getComment_text());
        postCommentViewHolder.tv_com3.setText(postCommentBean.getComment_time());
        id = postCommentBean.getComment_id();
        comment_text = postCommentBean.getComment_text();
        comment_time = postCommentBean.getComment_time();

    }

    public void setList(List<PostCommentBean> list){
        this.items = (List<PostCommentBean>) list;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        if (items == null)
            return 0;
        else {
            return items.size();
        }
    }
}
